<?php

/**
 * Class Lib_Repair_Adapter_LianTong
 * 联通失联修复
 * 2020/11/06
 */
class Lib_Repair_Implement_LianTong extends Lib_Repair_Base_LT
{
    private static $obj = null;

    /**
     * 单例获取
     * @return Lib_Repair_Implement_LianTong
     */
    public static function getInstance(){
        if (is_null(self::$obj)) {
            self::$obj = new self();
        }
        return self::$obj;
    }
    /**
     * 修复接口
     * @param $data
     * @return array
     */
    public function repair($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            return $this->returnData(400,'empty post data');
        }
        //接口发送
        return $this->curlPost('/repair/verifyPhoneRepair', $post_data);
    }
    /**
     * 获取修复结果接口
     * @param $data
     * @return array
     */
    public function getRepairResult($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            return $this->returnData(400,'empty post data');
        }
        //接口发送
        return $this->curlPost('/getRepairResult', $post_data);
    }

    /**
     * 查询修复结果
     * @param $data
     * @return array
     */
    public function queryPhoneNum($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            return $this->returnData(400,'empty post data');
        }
        //接口发送
        return $this->curlPost('/call/queryPhoneNum', $post_data);
    }
    /**
     * 绑定虚拟小号接口
     * @param $data
     * @return array
     */
    public function binding($data) {
        $telX = $this->getTelX();
        if(!$telX){
            return $this->returnData(401,'暂没有空余的中间号码绑定，稍后再试！');
        }
        $data['telX'] = $telX;
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            Func_Log::write('curl',   'curl_end', json_encode($data).json_encode($post_data));
            return $this->returnData(400,'绑定中间号码参数有误！');
        }
        Lib_Redis_Set::sAdd(Lib_Repair_Adapter_LianTong::$telX_set_key,$telX);
        //接口发送
        $resData = $this->curlPost('/call/axb/binding', $post_data);
        if($resData['code'] == '000') {
            $resData['data']['pass'] = 'LianTong';
            Lib_Redis_String::setex("bind_".$telX,3600,json_encode($resData['data']));
        }else{
            Lib_Redis_Set::sRem(Lib_Repair_Adapter_LianTong::$telX_set_key,$telX);
        }
        return $resData;
    }
    /**
     * 解绑虚拟小号接口
     * @param $data
     * @return array
     */
    public function unbinding($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            return $this->returnData(400,'empty post data');
        }
        //接口发送
        return $this->curlPost('/call/axb/unbinding', $post_data);
    }
    /**
     * 发送短信
     * @param $data
     * @return array
     */
    public function sendMessageData($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            Func_Log::write('repair',   'liantong',"send sms -- empty post data ".' responsedata: '. json_encode($data)."buildData: ".json_encode($post_data));

            return $this->returnData(400,'empty post data');
        }
        //接口发送
        return $this->curlPost('/sendMessageData', $post_data);
    }

}